package logic

import (
	"context"
	"product/goodrpc/goodrpcclient"

	"product/api/internal/svc"
	"product/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateLogic) Update(req *types.UpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.GoodRpc.Update(l.ctx, &goodrpcclient.UpdateRequest{
		Id:       int64(req.Id),
		Userid:   int64(req.Userid),
		Name:     req.Name,
		Image:    req.Image,
		Quantity: int64(req.Quantity),
		Price:    int64(req.Price),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "商品信息修改成功",
		Code:    200,
		Data:    update,
	}, nil
}
